package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsInventory;
import com.ruoyi.wms.service.IWmsInventoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/inventory")
public class WmsInventoryController extends BaseController
{
    @Autowired
    private IWmsInventoryService wmsInventoryService;

    /**
     * 查询库存列表
     */
    @PreAuthorize(hasPermi = "wms:inventory:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsInventory wmsInventory)
    {
        startPage();
        List<WmsInventory> list = wmsInventoryService.selectWmsInventoryList(wmsInventory);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @PreAuthorize(hasPermi = "wms:inventory:export")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInventory wmsInventory) throws IOException
    {
        List<WmsInventory> list = wmsInventoryService.selectWmsInventoryList(wmsInventory);
        ExcelUtil<WmsInventory> util = new ExcelUtil<WmsInventory>(WmsInventory.class);
        util.exportExcel(response, list, "库存数据");
    }

    /**
     * 获取库存详细信息
     */
    @PreAuthorize(hasPermi = "wms:inventory:query")
    @GetMapping(value = "/{inventoryUuid}")
    public AjaxResult getInfo(@PathVariable("inventoryUuid") String inventoryUuid)
    {
        return AjaxResult.success(wmsInventoryService.selectWmsInventoryByInventoryUuid(inventoryUuid));
    }

    /**
     * 新增库存
     */
    @PreAuthorize(hasPermi = "wms:inventory:add")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsInventory wmsInventory)
    {
        return toAjax(wmsInventoryService.insertWmsInventory(wmsInventory));
    }

    /**
     * 修改库存
     */
    @PreAuthorize(hasPermi = "wms:inventory:edit")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsInventory wmsInventory)
    {
        return toAjax(wmsInventoryService.updateWmsInventory(wmsInventory));
    }

    /**
     * 删除库存
     */
    @PreAuthorize(hasPermi = "wms:inventory:remove")
    @Log(title = "库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryUuids}")
    public AjaxResult remove(@PathVariable String[] inventoryUuids)
    {
        return toAjax(wmsInventoryService.deleteWmsInventoryByInventoryUuids(inventoryUuids));
    }
}
